package com.lysj.admin.master.bussiness.company.invoice.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lysj.admin.master.bussiness.company.invoice.domain.InvoiceApplyItem;
import com.lysj.admin.master.bussiness.company.invoice.dto.InvoiceApplyItemQueryDto;
import com.lysj.admin.master.bussiness.company.invoice.dto.InvoiceApplyItemSubmitDto;
import com.lysj.admin.master.bussiness.company.invoice.mapper.InvoiceApplyItemMapper;
import com.lysj.admin.master.bussiness.company.invoice.service.InvoiceApplyItemService;
import com.lysj.admin.master.common.annotation.MyList;
import com.lysj.admin.master.common.enumeration.EnumUtils;
import com.lysj.admin.master.common.spring.mpbase.MyController;
import com.lysj.admin.master.common.spring.mpbase.MyService;
import com.lysj.admin.master.common.spring.pagination.PageRequestDTO;
import com.lysj.admin.master.common.validation.annotation.Valid;
import com.lysj.admin.master.common.web.Resp;
import com.lysj.admin.master.common.web.RespUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Created by drj on 2020-01-09 10:48
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/company/invoice_apply_item")
public class InvoiceApplyItemController extends MyController<InvoiceApplyItemMapper, InvoiceApplyItem, PageRequestDTO> {

    @Resource
    private InvoiceApplyItemService invoiceApplyItemService;

    @Override
    public MyService<InvoiceApplyItemMapper, InvoiceApplyItem> getService() {
        return invoiceApplyItemService;
    }


    @MyList
    public Resp list(InvoiceApplyItemQueryDto condition) {
        Page<InvoiceApplyItem> invoiceApplyItemRecordPage = getService().pageList(condition);
        for (InvoiceApplyItem invoiceApplyItem : invoiceApplyItemRecordPage.getRecords()) {
            invoiceApplyItem.setInvoiceStatusTxt(EnumUtils.findStatusByCode(invoiceApplyItem.getInvoiceStatus(),
                    InvoiceApplyItem.InvoiceStatus.class));
        }
        return RespUtil.success(invoiceApplyItemRecordPage);
    }


    @PostMapping("/audit")
    public Resp audit(String id, Integer invoiceStatus) {
        return RespUtil.success(invoiceApplyItemService.audit(id, invoiceStatus));
    }


    /*
     * @author Created by drj on 2020/1/9 11:19
     * @Description :提交开票申请子项
     */
    @PostMapping("/submit")
    public Resp submit(@Valid InvoiceApplyItemSubmitDto model) {
       return RespUtil.success(invoiceApplyItemService.submit(model)) ;
    }

}
